package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishFlavorMapper {

    /*
     * 根据categoryId查询所在行id
     * */
    @Select("select id from dish where name=#{name}")
    Long selectIdByName (String name);

    /*
     * 添加口味数据
     * */
//    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into dish_flavor (id, dish_id,name, value)" +
            "values"+"(#{id},#{dishId},#{name},#{value})")
    void saveFlavor(DishFlavor dishFlavor);

    /*
    * 根据dishId删除菜品对应口味数据
    * */
    @Delete("delete from dish_flavor where dish_id=#{dishId}")
    void deleteByDishId(Long dishId);

    /*
    * 根据dish_id批量删除菜品对应口味数据
    * */
    void deleteBatchByDishIds(List<Long> ids);

    /*
    * 根据菜品id查询对应的口味数据
    * */
    List<DishFlavor> getFlavorById(Long id);

    /*
    *根据id修改对应行菜品口味数据
    * */
//    @AutoFill(OperationType.UPDATE)//哥们，你添加个鸡毛啊 你都没这功能哈哈哈
    void update(DishFlavor dishFlavor);

    @Select("select exists(select * from dish_flavor where id = #{id})")
    Integer getById(Long id);

    /*
    * 根据菜品口味名称name来查询此口味是否存在
    * */
    @Select("select exists(select * from dish_flavor where dish_id=#{dishId} and name=#{name}")
    Integer getByName(DishFlavor dishFlavor);

    /*
    * 根据name来修改口味数据
    * */
    void updateyName(DishFlavor dishFlavor);
}
